#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
int n;
vector<int> a;
int f = 0;
signed main()
{
    cin >> n;
    int size = n;
    for(int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(), a.end());
    int l = 0, r = size - 1;
    int k = 1;
    int ans = a[r] * a[r];
    while(k <= size) {
        ans += (a[r] - a[l]) * (a[r] - a[l]);
        k++;
        if(f) {
            l++;
            f = 0;
        }else{
            r--;
            f = 1;
        }
    }
    cout << ans << endl;
    return 0;
}